package com.itheima.myreflect2.Student;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @program: Myset
 * @description:
 * @author: xuejingjing
 * @create: 2021-06-15 22:20
 **/
public class CharStreamDemo12 {
    public static void main(String[] args) throws IOException {
        //字符缓冲流的特有功能
        //字符缓冲输入流BufferedReader： readLine:读一整行
        method1();

        //使用循环改进
        BufferedReader br = new BufferedReader(new FileReader("a.txt"));
        String line;
        //可以读取一整行数据，一直读，读到回车换行为止。
        while ((line = br.readLine())!=null){
            System.out.println(line);
        }

        br.close();

    }

    private static void method1() throws IOException {

        BufferedReader br = new BufferedReader(new FileReader("a.txt"));  //创建对象
        //创建对象

        //读取数据，读到内存
        String line1  = br.readLine();
        String line2  = br.readLine();
        String line3  = br.readLine();

        //在之前，如果读不到数据，返回-1
        //但是readLine如果读不到数据，返回null
        String line4 = br.readLine();
        String line5 = br.readLine();

        System.out.println(line1);
        System.out.println(line2);
        System.out.println(line3);
        System.out.println(line4);
        System.out.println(line5);
    }
}
